<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="pro.name">
  <input type="text" placeholder="请输入员工工资" v-model="pro.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="pro.job">
  <button @click="add">添加员工</button>
  <hr>
  <table border="1px">
    <caption>员工表</caption>
    <tr>
      <th>编号</th>
      <th>姓名</th>
      <th>工资</th>
      <th>岗位</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{ index + 1 }}</td>
      <td>{{ item.name }}</td>
      <td>{{ item.salary }}</td>
      <td>{{ item.job }}</td>

    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const pro = ref({name: '', salary: '', job: ''});
const productArr = ref([]);
const add = () => {
  if (pro.value.name.trim()==''||pro.value.salary.trim()==''||pro.value.job.trim()==''){
    alert('请输入数据');
    return;
  }
  productArr.value.push(pro.value);
  pro.value={name: '', salary: '', job: ''};
  console.log(productArr.value);
}
</script>


<style scoped>

</style>